﻿#include "dialogtip.h"
#include "ui_dialogtip.h"
#include <QDebug>

#pragma execution_character_set("utf-8")

DialogTip::DialogTip(QWidget *parent,QString strTip,int iTime) :
    QDialog(parent),
    ui(new Ui::DialogTip)
{
    ui->setupUi(this);
    //this->setAttribute(Qt::WA_DeleteOnClose);

    if(iTime<0)
        ui->lbIcon->setPixmap(QPixmap(":/new/prefix1/res/error.png"));
    ui->lbTip->setText(strTip);
    iTimeOut=abs(iTime);
    if(iTimeOut > 0)
    {
        QString str;
        str.sprintf("关闭(%d)",iTimeOut);
        ui->pbOk->setText(str);

        //定时器
        timer=new QTimer(this);
        connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
        timer->start(1000);
    }
    else
        ui->pbOk->setText("关闭");

    if(strTip.indexOf('\n')>0)
        ui->lbTip->setAlignment(Qt::AlignLeft);
    else
        ui->lbTip->setAlignment(Qt::AlignCenter);
}

DialogTip::~DialogTip()
{
    delete ui;
}

void DialogTip::onTimer()
{
    iTimeOut --;
    if(iTimeOut > 0)
    {
        QString str;
        str.sprintf("关闭(%d)",iTimeOut);
        ui->pbOk->setText(str);
    }
    else
        this->close();
}

void DialogTip::on_pbOk_clicked()
{
    this->close();
}
